package com.golden.procedure.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.golden.procedure.dao.SiteSchedulingTemplateDetailMapper;
import com.golden.procedure.dao.WorkSeatSchedulingMapper;
import com.golden.procedure.dao.WorkSiteSchedulingMapper;
import com.golden.procedure.dao.WorkSiteSeatMapper;
import com.golden.procedure.domain.WorkSchedulingSettingDO;
import com.golden.procedure.domain.WorkSeatSchedulingDO;
import com.golden.procedure.entity.WorkSeatScheduling;
import com.golden.procedure.entity.WorkSeatSchedulingExample;
import com.golden.procedure.entity.WorkSiteSeat;
import com.golden.procedure.entity.WorkSiteSeatExample;
import com.golden.procedure.query.SchedulingQueryDO;
import com.golden.procedure.result.ResultDO;
import com.golden.procedure.result.ResultSupport;
import com.golden.procedure.service.IWorkSeatSchedulingService;
import com.golden.procedure.service.IWorkSiteSeatService;
import com.golden.procedure.util.BeanUtilsExtends;
import com.golden.procedure.util.BonConstant;

@Service("workSeatSchedulingService")
public class WorkSeatSchedulingService extends BaseService implements IWorkSeatSchedulingService {

	@Autowired
	WorkSiteSeatMapper workSiteSeatMapper;
	@Autowired
	WorkSiteSchedulingMapper workSiteSchedulingMapper;
	@Autowired
	WorkSeatSchedulingMapper workSeatSchedulingMapper;
	@Autowired
	SiteSchedulingTemplateDetailMapper templateDetailMapper;
	@Autowired
	IWorkSiteSeatService workSiteSeatService;

	/**
	 * 席位查询 <b>Description:</b><br>
	 * 
	 * @param queryDO
	 * @return ResultDO
	 * @Note <b>Author:</b> Reading.Reagan <br>
	 *       <b>Date:</b> 2018年9月26日 上午11:00:14 <br>
	 *       <b>Version:</b> 1.0
	 */
	@Override
	public ResultDO query(SchedulingQueryDO queryDO) {
		ResultDO result = new ResultSupport();

		WorkSeatSchedulingExample example = new WorkSeatSchedulingExample();
		WorkSeatSchedulingExample.Criteria criteria = example.createCriteria();
		if (!isNumberInValid(queryDO.getSiteID())) {
			criteria.andSiteIDEqualTo(queryDO.getSiteID());
		}
		if (!isNumberInValid(queryDO.getSiteSeatID())) {
			criteria.andSiteSeatIDEqualTo(queryDO.getSiteSeatID());
		}
		if (null != queryDO.getSiteSeatIDs() && queryDO.getSiteSeatIDs().length > 0) {
			criteria.andSiteSeatIDIn(Arrays.asList(queryDO.getSiteSeatIDs()));
		}
		if (StringUtils.isNotEmpty(queryDO.getSchedulingDateStart())
				&& StringUtils.isNotEmpty(queryDO.getSchedulingDateEnd())) {
			Date startDate = new Date(Long.parseLong(queryDO.getSchedulingDateStart()));
			Date endDate = new Date(Long.parseLong(queryDO.getSchedulingDateEnd()));
			criteria.andSchedulingDateBetween(startDate, endDate);
		}
		// 跳过禁用的席位
		criteria.andStatusNotEqualTo(BonConstant.SEAT_STATUS_DISABLE);
		criteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);
		example.setOrderByClause(" schedulingDate asc, seatGroupIndex asc, planStartOn asc ");

		if (queryDO.isPage()) {
			example.setLimitByPage(queryDO.getStart() + "," + queryDO.getPageRows());
			int count = workSeatSchedulingMapper.countByExample(example);
			result.setModel(ResultDO.SECOND_MODEL_KEY, count);
		}

		List<WorkSeatScheduling> seatList = workSeatSchedulingMapper.selectByExample(example);
		if (null == seatList || seatList.size() < 1) {
			result.setModel(ResultDO.FIRST_MODEL_KEY, new ArrayList<WorkSeatSchedulingDO>());
		} else {
			result.setModel(ResultDO.FIRST_MODEL_KEY, getWorkSeatSchedulingDOList(seatList));
		}
		return result;
	}

	/**
	 * 时段查重 <b>Description:</b><br>
	 * 
	 * @param domain
	 * @return int
	 * @Note <b>Author:</b> Reading.Reagan <br>
	 *       <b>Date:</b> 2018年9月26日 上午11:06:20 <br>
	 *       <b>Version:</b> 1.0
	 */
	@Override
	public int checkDuplicatePlanStartOn(WorkSchedulingSettingDO domain) {

		WorkSeatSchedulingExample example = new WorkSeatSchedulingExample();
		WorkSeatSchedulingExample.Criteria criteria = example.createCriteria();
		criteria.andSiteIDEqualTo(domain.getSiteID());
		criteria.andSiteSeatIDEqualTo(domain.getSiteSeatID());
		try {
			Date planStartOn = new SimpleDateFormat("HH:mm").parse(domain.getPlanStartOnStr());
			criteria.andPlanStartOnEqualTo(planStartOn);
		} catch (ParseException e1) {
			return -1;
		}
		criteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);
		List<WorkSeatScheduling> list = workSeatSchedulingMapper.selectByExample(example);
		if (null != list && list.size() > 0) {
			return 1;
		}
		return 0;
	}

	/**
	 * 查询制定时间段内或指定工位下的席位是否已被占用<b>Description:</b><br>
	 * 
	 * @param domain
	 * @return boolean true-席位空闲；false-席位已被占用；
	 * @Note <b>Author:</b> Reading.Reagan <br>
	 *       <b>Date:</b> 2018年9月26日 上午11:06:20 <br>
	 *       <b>Version:</b> 1.0
	 */
	@Override
	public boolean checkSeatEnable(WorkSchedulingSettingDO domain) {
		WorkSeatSchedulingExample seatExample = new WorkSeatSchedulingExample();
		WorkSeatSchedulingExample.Criteria seatCriteria = seatExample.createCriteria();
		if (!isNumberInValid(domain.getSiteID())) {
			seatCriteria.andSiteIDEqualTo(domain.getSiteID());
		}
		if (!isNumberInValid(domain.getSiteSeatID())) {
			seatCriteria.andSiteSeatIDEqualTo(domain.getSiteSeatID());
		}
		if (StringUtils.isNotEmpty(domain.getSchedulingDateStart())
				&& StringUtils.isNotEmpty(domain.getSchedulingDateEnd())) {
			seatCriteria.andSchedulingDateBetween(new Date(Long.parseLong(domain.getSchedulingDateStart())),
					new Date(Long.parseLong(domain.getSchedulingDateEnd())));
		}
		if (!isNumberInValid(domain.getSeatGroupIndex())) {
			seatCriteria.andSeatGroupIndexEqualTo(domain.getSeatGroupIndex());
		}
		if (StringUtils.isNotEmpty(domain.getPlanStartOnStr())) {
			try {
				Date planStartOn = new SimpleDateFormat("HH:mm").parse(domain.getPlanStartOnStr());
				seatCriteria.andPlanStartOnEqualTo(planStartOn);
			} catch (ParseException e1) {
				// 参数错误
				return false;
			}
		}
		seatCriteria.andStatusEqualTo(BonConstant.SEAT_STATUS_USED); // 1 占用
		seatCriteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);
		List<WorkSeatScheduling> seatList = workSeatSchedulingMapper.selectByExample(seatExample);
		if (null != seatList && seatList.size() > 0) {
			return false;
		}
		return true;
	}

	/**
	 * 添加席位 <b>Description:某一天或某个时间段内，相同的工位分组增加席位</b><br>
	 * 
	 * @param domain
	 * @return ResultDO
	 * @Note <b>Author:</b> Reading.Reagan <br>
	 *       <b>Date:</b> 2018年9月17日 下午5:31:40 <br>
	 *       <b>Version:</b> 1.0
	 */
	@Override
	public ResultDO addSeat(WorkSchedulingSettingDO domain) {
		ResultDO result = new ResultSupport();
		// 1.基础数据验证
		if (isNumberInValid(domain.getSiteID())) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("上门组ID为空");
			result.setSuccess(false);
			return result;
		}

		// 2.查询时段数据是否重复
		int ret = checkDuplicatePlanStartOn(domain);
		if (ret == -1) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("拍摄时段格式错误");
			result.setSuccess(false);
			return result;
		} else if (ret == 1) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("拍摄时段重复");
			result.setSuccess(false);
			return result;
		}

		// 3.根据工位分组id查询工位分组序号
		WorkSiteSeat siteSeat = workSiteSeatMapper.selectByPrimaryKey(domain.getSiteSeatID());
		if (null == siteSeat) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("工位分组ID错误");
			result.setSuccess(false);
			return result;
		}

		// 4.根据日程id、工位分组序号，查询工位分组列表
		WorkSiteSeatExample siteSeatExample = new WorkSiteSeatExample();
		WorkSiteSeatExample.Criteria siteSeatCriteria = siteSeatExample.createCriteria();
		siteSeatCriteria.andSiteIDEqualTo(domain.getSiteID());
		siteSeatCriteria.andSchedulingDateBetween(new Date(Long.parseLong(domain.getSchedulingDateStart())),
				new Date(Long.parseLong(domain.getSchedulingDateEnd())));
		siteSeatCriteria.andSeatGroupIndexEqualTo(siteSeat.getSeatGroupIndex());
		siteSeatCriteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);

		List<WorkSiteSeat> siteSeatList = workSiteSeatMapper.selectByExample(siteSeatExample);
		// 5.根据工位分组添加席位数据
		Date planStartOn = null;
		try {
			planStartOn = new SimpleDateFormat("HH:mm").parse(domain.getPlanStartOnStr());
		} catch (ParseException e) {
			e.printStackTrace();
		}
		for (WorkSiteSeat data : siteSeatList) {
			WorkSeatScheduling seatScheduling = new WorkSeatScheduling();
			seatScheduling.setSiteID(data.getSiteID());
			seatScheduling.setSiteSchedulingID(data.getSiteSchedulingID());
			seatScheduling.setSiteSeatID(data.getId());
			seatScheduling.setSeatGroupIndex(data.getSeatGroupIndex());
			seatScheduling.setSchedulingDate(data.getSchedulingDate());
			seatScheduling.setPlanStartOn(planStartOn);
			seatScheduling.setStatus(BonConstant.SEAT_STATUS_ENABLE);
			seatScheduling.setIsDelete(BonConstant.DB_NORMAL);
			// 创建信息
			seatScheduling.setCreatetime(Calendar.getInstance().getTime());
			seatScheduling.setAuthorID(domain.getAuthorID());
			seatScheduling.setAuthor(domain.getAuthor());
			workSeatSchedulingMapper.insert(seatScheduling);
		}

		return result;
	}

	/**
	 * 编辑 <b>Description:</b><br>
	 * 
	 * @param seatSchedulingDO
	 * @return ResultDO
	 * @Note <b>Author:</b> Reading.Reagan <br>
	 *       <b>Date:</b> 2018年9月26日 上午10:57:31 <br>
	 *       <b>Version:</b> 1.0
	 */
	@Override
	public ResultDO edit(WorkSeatSchedulingDO seatSchedulingDO) {
		ResultDO result = new ResultSupport();
		// 1.基础数据验证
		WorkSeatScheduling entity = new WorkSeatScheduling();
		if (!BeanUtilsExtends.copyProperties(entity, seatSchedulingDO)) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("数据转换失败");
			result.setSuccess(false);
			return result;
		}

		entity.setModifitime(Calendar.getInstance().getTime());
		int ret = workSeatSchedulingMapper.updateByPrimaryKeySelective(entity);
		if (ret < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("席位更新失败");
			result.setSuccess(false);
			return result;
		}
		return result;
	}

	@Override
	public ResultDO listBySiteSeatID(Integer siteSeatID) {
		ResultDO result = new ResultSupport();
		// 1.基础数据验证
		if (isNumberInValid(siteSeatID)) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("工位分组ID为空");
			result.setSuccess(false);
			return result;
		}

		WorkSeatSchedulingExample example = new WorkSeatSchedulingExample();
		WorkSeatSchedulingExample.Criteria criteria = example.createCriteria();
		criteria.andSiteSeatIDEqualTo(siteSeatID);
		criteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);
		example.setOrderByClause(" schedulingDate asc, seatGroupIndex asc, planStartOn asc ");

		List<WorkSeatScheduling> seatList = workSeatSchedulingMapper.selectByExample(example);
		if (null == seatList || seatList.size() < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("席位不存在");
			result.setSuccess(false);
		} else {
			result.setModel(ResultDO.FIRST_MODEL_KEY, getWorkSeatSchedulingDOList(seatList));
		}
		return result;
	}

	@Override
	public ResultDO get(Integer id) {
		ResultDO result = new ResultSupport();
		// 1.基础数据验证
		if (isNumberInValid(id)) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("席位ID为空");
			result.setSuccess(false);
			return result;
		}

		WorkSeatScheduling seat = workSeatSchedulingMapper.selectByPrimaryKey(id);
		if (null == seat || seat.getIsDelete() == BonConstant.DB_DELETE) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("席位不存在");
			result.setSuccess(false);
		} else {
			result.setModel(ResultDO.FIRST_MODEL_KEY, getWorkSeatSchedulingDO(seat));
		}
		return result;
	}

	/**
	 * 编辑席位 <b>Description:某一天或某个时间段内，编辑相同的工位分组的席位拍摄时间</b><br>
	 * 
	 * @param domain
	 * @return ResultDO
	 * @Note <b>Author:</b> Reading.Reagan <br>
	 *       <b>Date:</b> 2018年9月17日 下午5:31:40 <br>
	 *       <b>Version:</b> 1.0
	 */
	@Override
	public ResultDO editSeat(WorkSchedulingSettingDO domain) {
		ResultDO result = new ResultSupport();
		// 1.基础数据验证
		if (isNumberInValid(domain.getSiteID())) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("上门组ID为空");
			result.setSuccess(false);
			return result;
		}

		// 2.查询时段数据是否重复
		int ret = checkDuplicatePlanStartOn(domain);
		if (ret == -1) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("拍摄时段格式错误");
			result.setSuccess(false);
			return result;
		} else if (ret == 1) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("拍摄时段重复");
			result.setSuccess(false);
			return result;
		}

		// 3.根据工位分组id查询工位分组序号
		WorkSiteSeat siteSeat = workSiteSeatMapper.selectByPrimaryKey(domain.getSiteSeatID());
		if (null == siteSeat) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("工位分组ID错误");
			result.setSuccess(false);
			return result;
		}

		// 日期格式转换
		Date oldPlanStartOn = null;
		Date planStartOn = null;
		try {
			oldPlanStartOn = new SimpleDateFormat("HH:mm").parse(domain.getOldPlanStartOn());
			planStartOn = new SimpleDateFormat("HH:mm").parse(domain.getPlanStartOnStr());
		} catch (ParseException e1) {
			// 参数错误
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("拍摄时段格式错误");
			result.setSuccess(false);
			return result;
		}

		// 批量更新
		WorkSeatSchedulingExample seatExample = new WorkSeatSchedulingExample();
		WorkSeatSchedulingExample.Criteria seatCriteria = seatExample.createCriteria();
		seatCriteria.andSiteIDEqualTo(domain.getSiteID());
		seatCriteria.andSchedulingDateBetween(new Date(Long.parseLong(domain.getSchedulingDateStart())),
				new Date(Long.parseLong(domain.getSchedulingDateEnd())));
		seatCriteria.andSeatGroupIndexEqualTo(siteSeat.getSeatGroupIndex());
		seatCriteria.andPlanStartOnEqualTo(oldPlanStartOn);
		seatCriteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);

		WorkSeatScheduling seatScheduling = new WorkSeatScheduling();
		seatScheduling.setPlanStartOn(planStartOn);
		// 更新人员
		seatScheduling.setModifitime(Calendar.getInstance().getTime());
		seatScheduling.setModifiID(domain.getModifiID());
		seatScheduling.setModifi(domain.getModifi());

		workSeatSchedulingMapper.updateByExampleSelective(seatScheduling, seatExample);

		return result;
	}

	/**
	 * 设置席位状态 <b>Description:某一天或某个时间段内，设置相同的工位分组的席位状态（启用或禁用）</b><br>
	 * 
	 * @param domain
	 * @return ResultDO
	 * @Note <b>Author:</b> Reading.Reagan <br>
	 *       <b>Date:</b> 2018年9月17日 下午5:31:40 <br>
	 *       <b>Version:</b> 1.0
	 */
	@Override
	public ResultDO seatStatus(WorkSchedulingSettingDO domain) {
		ResultDO result = new ResultSupport();
		// 1.基础数据验证
		if (isNumberInValid(domain.getSiteID())) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("上门组ID为空");
			result.setSuccess(false);
			return result;
		}

		// 2.时段数据
		Date planStartOn = null;
		try {
			planStartOn = new SimpleDateFormat("HH:mm").parse(domain.getPlanStartOnStr());
		} catch (ParseException e1) {
			// 参数错误
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("拍摄时段格式错误");
			result.setSuccess(false);
			return result;
		}

		// 3.根据工位分组id查询工位分组序号
		WorkSiteSeat siteSeat = workSiteSeatMapper.selectByPrimaryKey(domain.getSiteSeatID());
		if (null == siteSeat) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("工位分组ID错误");
			result.setSuccess(false);
			return result;
		}

		// 4. 禁用时判断席位是否被占用
		if (domain.getStatus() == -1) {
			WorkSchedulingSettingDO settingDO = new WorkSchedulingSettingDO();
			if (!BeanUtilsExtends.copyProperties(settingDO, domain)) {
				result.setErrorCode(ResultDO.PARAM_ERROR);
				result.setErrorMsg("工位分组ID错误");
				result.setSuccess(false);
				return result;
			}
			settingDO.setSiteSeatID(null);
			settingDO.setSeatGroupIndex(siteSeat.getSeatGroupIndex());
			if (!checkSeatEnable(settingDO)) {
				result.setErrorCode(ResultDO.PARAM_ERROR);
				result.setErrorMsg("该席位已有工单预约，不可禁用");
				result.setSuccess(false);
				return result;
			}
		}

		// 启用或禁用席位
		WorkSeatSchedulingExample seatExample = new WorkSeatSchedulingExample();
		WorkSeatSchedulingExample.Criteria seatCriteria = seatExample.createCriteria();
		seatCriteria.andSiteIDEqualTo(domain.getSiteID());
		seatCriteria.andSchedulingDateBetween(new Date(Long.parseLong(domain.getSchedulingDateStart())),
				new Date(Long.parseLong(domain.getSchedulingDateEnd())));
		seatCriteria.andSeatGroupIndexEqualTo(siteSeat.getSeatGroupIndex());
		seatCriteria.andPlanStartOnEqualTo(planStartOn);
		seatCriteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);

		WorkSeatScheduling seatScheduling = new WorkSeatScheduling();
		seatScheduling.setStatus(domain.getStatus());
		seatScheduling.setModifitime(Calendar.getInstance().getTime());
		seatScheduling.setModifiID(domain.getModifiID());
		seatScheduling.setModifi(domain.getModifi());
		workSeatSchedulingMapper.updateByExampleSelective(seatScheduling, seatExample);

		return result;
	}

	/**
	 * 批量删除席位 <b>Description:通过席位id批量删除</b><br>
	 * 
	 * @param ids
	 * @param modifiID
	 * @param modifi
	 * @return ResultDO
	 * @Note <b>Author:</b> Reading.Reagan <br>
	 *       <b>Date:</b> 2018年9月28日 下午2:59:19 <br>
	 *       <b>Version:</b> 1.0
	 */
	@Override
	public ResultDO deleteByIds(List<Integer> ids, Integer modifiID, String modifi) {
		// TODO Auto-generated method stub
		ResultDO result = new ResultSupport();
		// 1.参数验证
		if (null == ids || ids.size() < 1) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			return result;
		}

		WorkSeatSchedulingExample seatExample = new WorkSeatSchedulingExample();
		WorkSeatSchedulingExample.Criteria seatCriteria = seatExample.createCriteria();
		seatCriteria.andSiteSeatIDIn(ids);
		seatCriteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);

		WorkSeatScheduling entity = new WorkSeatScheduling();
		entity.setIsDelete(BonConstant.DB_DELETE);
		entity.setModifiID(modifiID);
		entity.setModifi(modifi);
		entity.setModifitime(Calendar.getInstance().getTime());
		workSeatSchedulingMapper.updateByExampleSelective(entity, seatExample);

		return result;
	}

	/**
	 * 摄控设置时，删除摄控期间内指定工位的指定席位
	 * 
	 * @Method: deleteSeat
	 * @Description: TODO
	 * @param domain
	 * @return
	 * @see com.golden.procedure.service.IWorkSeatSchedulingService#deleteSeat(com.golden.procedure.domain.WorkSchedulingSettingDO)
	 */
	@Override
	public ResultDO deleteSeat(WorkSchedulingSettingDO domain) {
		ResultDO result = new ResultSupport();
		// 1.基础数据验证
		if (isNumberInValid(domain.getSiteID()) || StringUtils.isEmpty(domain.getPlanStartOnStr())
				|| StringUtils.isEmpty(domain.getSchedulingDateStart())
				|| StringUtils.isEmpty(domain.getSchedulingDateEnd())) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			return result;
		}

		// 2.时段数据
		Date planStartOn = null;
		try {
			planStartOn = new SimpleDateFormat("HH:mm").parse(domain.getPlanStartOnStr());
		} catch (ParseException e1) {
			// 参数错误
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("拍摄时段格式错误");
			result.setSuccess(false);
			return result;
		}

		// 3.根据工位分组id查询工位分组序号
		WorkSiteSeat siteSeat = workSiteSeatMapper.selectByPrimaryKey(domain.getSiteSeatID());
		if (null == siteSeat) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("工位分组ID错误");
			result.setSuccess(false);
			return result;
		}

		// 4. 判断席位是否被占用
		WorkSchedulingSettingDO settingDO = new WorkSchedulingSettingDO();
		if (!BeanUtilsExtends.copyProperties(settingDO, domain)) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("工位分组ID错误");
			result.setSuccess(false);
			return result;
		}
		settingDO.setSiteSeatID(null);
		settingDO.setSeatGroupIndex(siteSeat.getSeatGroupIndex());
		if (!checkSeatEnable(settingDO)) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("该席位已有工单预约，不可删除");
			result.setSuccess(false);
			return result;
		}

		// 5.删除席位
		WorkSeatSchedulingExample seatExample = new WorkSeatSchedulingExample();
		WorkSeatSchedulingExample.Criteria seatCriteria = seatExample.createCriteria();
		seatCriteria.andSiteIDEqualTo(domain.getSiteID());
		seatCriteria.andSchedulingDateBetween(new Date(Long.parseLong(domain.getSchedulingDateStart())),
				new Date(Long.parseLong(domain.getSchedulingDateEnd())));
		seatCriteria.andPlanStartOnEqualTo(planStartOn);
		seatCriteria.andSeatGroupIndexEqualTo(siteSeat.getSeatGroupIndex());
		seatCriteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);

		WorkSeatScheduling seatScheduling = new WorkSeatScheduling();
		seatScheduling.setIsDelete(BonConstant.DB_DELETE);
		seatScheduling.setModifitime(Calendar.getInstance().getTime());
		seatScheduling.setModifiID(domain.getModifiID());
		seatScheduling.setModifi(domain.getModifi());
		workSeatSchedulingMapper.updateByExampleSelective(seatScheduling, seatExample);

		return result;
	}

}
